﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;


namespace ditiexian
{
    public partial class Form1 : Form
    {
        struct pointxy
        {
            public double x;
            public double y;
        }
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            CreateChart();

        }

        private void CreateChart()
        {
            int d = 20;
            double a = 2.0*Math.PI / 180.0;
            double hj=1.2;
            pointxy[,] arr = new pointxy[3,319];
            //线段端点
            arr[0, 0].x = 0;
            arr[0, 0].y = 0;
            arr[1, 0].x = -d * Math.Sin(a);
            arr[1, 0].y = d * Math.Cos(a);
            arr[2, 0].x = -2 * d * Math.Sin(a);
            arr[2, 0].y = 2 * d * Math.Cos(a);
            //线段点
            for (int i = 1; i < 172; i++)
            {
                arr[0,i].x=((2*i-1)*hj*Math.Cos(a))/2;
                arr[0, i].y = ((2 * i - 1) * hj * Math.Sin(a)) / 2;
                arr[1, i].x = ((2 * i - 1) * hj * Math.Cos(a)) / 2 - d * Math.Sin(a);
                arr[1, i].y = ((2 * i - 1) * hj * Math.Sin(a)) / 2 + d * Math.Cos(a);
                arr[2, i].x = ((2 * i - 1) * hj * Math.Cos(a)) / 2 - 2*d * Math.Sin(a);
                arr[2, i].y = ((2 * i - 1) * hj * Math.Sin(a)) / 2 + 2*d * Math.Cos(a);
            }
            //线段末端
            arr[0, 172].x = 207.6 * Math.Cos(a);
            arr[0, 172].y = 207.6 * Math.Sin(a);
            arr[1, 172].x = 207.6 * Math.Cos(a) - d * Math.Sin(a) ;
            arr[1, 172].y = 207.6 * Math.Sin(a) + d * Math.Cos(a);
            arr[2, 172].x = 207.6 * Math.Cos(a) - 2*d * Math.Sin(a);
            arr[2, 172].y = 207.6 * Math.Sin(a) + 2*d * Math.Cos(a);

            //曲线段
            double I = 19.8;
            double R0 = 2003;
            double R1 = 2000;
            double R2 = 1997;
            double L = 0;
            double x0, y0, x1, y1, x2, y2, r0, r1, r2;
            for (int i1 = 173; i1 < 241; i1++)
            {
                L = (i1 - 173) * hj + hj / 2;
                x0 = L - Math.Pow(L, 5) / (40 * Math.Pow(R0, 2) * Math.Pow(I, 2));
                x1 = L - Math.Pow(L, 5) / (40 * Math.Pow(R1, 2) * Math.Pow(I, 2));
                x2 = L - Math.Pow(L, 5) / (40 * Math.Pow(R2, 2) * Math.Pow(I, 2));
                y0 = Math.Pow(L, 3) / (60 * R0 * I) - Math.Pow(L, 7) / (336 * Math.Pow(R0, 3) * Math.Pow(I, 3));
                y1 = Math.Pow(L, 3) / (60 * R1 * I) - Math.Pow(L, 7) / (336 * Math.Pow(R1, 3) * Math.Pow(I, 3));
                y2 = Math.Pow(L, 3) / (60 * R2 * I) - Math.Pow(L, 7) / (336 * Math.Pow(R2, 3) * Math.Pow(I, 3));
                r0 = Math.Atan(y0 / x0);
                r1 = Math.Atan(y1 / x1);
                r2 = Math.Atan(y2 / x2);
                arr[0, i1].x = Math.Sqrt(Math.Pow(x0, 2) + Math.Pow(y0, 2)) * Math.Cos(a + r0) + arr[0, 172].x;
                arr[0, i1].y = Math.Sqrt(Math.Pow(x0, 2) + Math.Pow(y0, 2)) * Math.Sin(a + r0) + arr[0, 172].y;
                arr[1, i1].x = Math.Sqrt(Math.Pow(x1, 2) + Math.Pow(y1, 2)) * Math.Cos(a + r1) + arr[1, 172].x;
                arr[1, i1].y = Math.Sqrt(Math.Pow(x1, 2) + Math.Pow(y1, 2)) * Math.Sin(a + r1) + arr[1, 172].y;
                arr[2, i1].x = Math.Sqrt(Math.Pow(x2, 2) + Math.Pow(y2, 2)) * Math.Cos(a + r2) + arr[2, 172].x;
                arr[2, i1].y = Math.Sqrt(Math.Pow(x2, 2) + Math.Pow(y2, 2)) * Math.Sin(a + r2) + arr[2, 172].y;
            }

            //最后一条直线
            double b = 4.0*Math.PI / 180.0;
            for (int i2 = 241; i2 < 319; i2++)
            {
                arr[0, i2].x = arr[0, 240].x + ((i2 - 241) * hj + hj / 2) * Math.Cos(b);
                arr[0, i2].y = arr[0, 240].y + ((i2 - 241) * hj + hj / 2) * Math.Sin(b);
                arr[1, i2].x = arr[0, 240].x + ((i2 - 241) * hj + hj / 2) * Math.Cos(b) - d * Math.Sin(b);
                arr[1, i2].y = arr[0, 240].y + ((i2 - 241) * hj + hj / 2) * Math.Sin(b) + d * Math.Cos(b);
                arr[2, i2].x = arr[0, 240].x + ((i2 - 241) * hj + hj / 2) * Math.Cos(b) - 2 * d * Math.Sin(b);
                arr[2, i2].y = arr[0, 240].y + ((i2 - 241) * hj + hj / 2) * Math.Sin(b) + 2 * d * Math.Cos(b);
            }

            

            //在图形上显示坐标点
            for (int m = 0; m < 3; m++)
            {
                for (int j = 0; j < 319; j++)
                {
                    chart1.Series[0].Points.AddXY(arr[m, j].x, arr[m, j].y);
                }
            }
        }

        private void chart1_PrePaint(object sender, ChartPaintEventArgs e)
        {
            Axis axis = this.chart1.ChartAreas[0].AxisX;
            double max = axis.Maximum;
            double min = axis.Minimum;
            this.chart1.ChartAreas[0].AxisY.Maximum = max;
            this.chart1.ChartAreas[0].AxisY.Minimum = min;
        }
        
    }
}
